package cn.edu.scau.cmi.xuandingcong.adapter;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Scanner;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class Controller  {

	 Map<Integer, String> map = new HashMap<Integer, String>();
	 List<Integer> list = new ArrayList<>();

	 Map<Integer, String> map2 = new HashMap<Integer, String>();
	 List<Integer> list2 = new ArrayList<>();
	@FXML
	private TextField idd;
	@FXML
	private	TextField name1;
	@FXML
	private TextField id2;
	@FXML
	private TextField name2;
	@FXML
	private TextArea ta1;
	@FXML
	private TextArea ta2;

	public void classAdapter() {
		StringBuffer text1 = new StringBuffer();
		
		
		if (idd.getText().trim().equals(""))
			text1.append("学号不能为空");
		else {
			Integer id = Integer.parseInt(idd.getText().trim());
			String name = name1.getText().trim();
			
			if (name.equals("")) {
				text1.append("学生名不能为空\n");
				for (int i = 0; i < map.size(); i++) {
					text1.append("学号：" + list.get(i) + "   姓名：" + map.get(list.get(i)) + "\n");
				}
			} else if (map.containsKey(id)) {
				text1.append("学号已存在！\n");
				for (int i = 0; i < map.size(); i++) {
					text1.append("学号：" + list.get(i) + "   姓名：" + map.get(list.get(i)) + "\n");
				}
			} else {
				text1.append("录入成功\n");
				list.add(id);
				map.put(id, name);
				list = new SortUtil().sortUtil(list);
				for (int i = 0; i < map.size(); i++) {
					text1.append("学号：" + list.get(i) + "   姓名：" + map.get(list.get(i)) + "\n");
				}

			}

		}
		ta1.setText(text1.toString());

	}

	public void objectAdapter() {
		StringBuffer text1 = new StringBuffer();

		if (id2.getText().trim().equals("")) {
			text1.append("学号不能为空");
			for (int i = 0; i < map2.size(); i++) {
				text1.append("学号：" + list2.get(i) + "   姓名：" + map2.get(list2.get(i)) + "\n");
			}
		}
			
		
		else {
			Integer id = Integer.parseInt(id2.getText().trim());
			String name = name2.getText().trim();
			
			if (name.equals("")) {
				text1.append("学生名不能为空\n");
				for (int i = 0; i < map2.size(); i++) {
					text1.append("学号：" + list2.get(i) + "   姓名：" + map2.get(list2.get(i)) + "\n");
				}
			} else if (map2.containsKey(id)) {
				text1.append("学生号已存在\n");
				for (int i = 0; i < map2.size(); i++) {
					text1.append("学号：" + list2.get(i) + "   姓名：" + map2.get(list2.get(i)) + "\n");
				}
			} else {
				text1.append("录入成功\n");
				list2.add(id);
				map2.put(id, name);
				list2 = new SortUtil().sortUtil(list2);// Ȼ������õı�ȥmap������name��Ȼ�����
				for (int i = 0; i < map2.size(); i++) {
					text1.append("学号：" + list2.get(i) + "   姓名：" + map2.get(list2.get(i)) + "\n");
				}

			}

		}
		ta2.setText(text1.toString());
	}



}
